<script lang="ts" setup>
  import { propTypes } from '@/utils/propTypes'
  import { ElButton } from 'element-plus'
  import { ensureElementPlusForComponent } from '@/utils/element-plus'
  import { getCurrentInstance } from 'vue'

  defineOptions({ name: 'EButton' })

  // 定义props
  const props = defineProps({
    preIcon: propTypes.string.def(''),
    postIcon: propTypes.string.def(''),
  })

  // 获取当前组件的应用实例
  const instance = getCurrentInstance()
  if (instance && instance.appContext.app) {
    // 确保ElButton组件可用
    ensureElementPlusForComponent(instance.appContext.app, ['ElButton'])
  }
</script>
<template>
  <el-button
    v-bind="$attrs"
    class="e-button"
  >
    <Icon v-if="preIcon" :icon="preIcon" class="mr-2px" />
    <slot></slot>
    <Icon v-if="postIcon" :icon="postIcon" class="mr-2px" />
  </el-button>
</template>
<style lang="scss" scoped>
  :deep(.e-button-middle, .el-button) {
    line-height: 32px;
    height: 32px;
    padding: 5px 16px;
    min-width: 90px;
    font-size: 14px;
  }
  :deep(.e-button-small, .el-button) {
    line-height: 24px;
    height: 24px;
    padding: 2px 12px;
    min-width: 48px;
    font-size: 12px;
  }
  :deep(.e-button, .el-button) {
    font-family: PingFang SC;
    font-weight: 500;
    line-height: 22px;
    text-align: center;
    text-underline-position: from-font;
    text-decoration-skip-ink: none;
  }
  :deep(.e-button, .el-button--primary) {
    background: #0f6cbd !important;
    color: #fff !important;
  }
  :deep(.e-button, .el-button--default) {
    border: 1px solid #dcdfe6;
    background-color: #ffffff;
    color: #242424;
  }
</style>
